<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>设置画布中图形的填充和笔触样式</title>
        <meta name="auther" content="wangjiale"/>
        <style>
            canvas{border:medium double black; margin:4px;}
        </style>
    </head>
    <body>
        <canvas id="canvas" width="500" height="140">
            Your browser doesn't support the <code>canvas</code> element.
        </canvas>
        <script>
            var ctx=document.getElementById("canvas").getContext("2d");
            var offset=10;
            var size=50;
            var count=5;
            ctx.lineWidth=3;
            var fillColors=["black","grey","lightgrey","red","blue"];
            var strokeColors=["rgb(0,0,0)","rgb(100,100,100)","rgb(200,200,200)","rgb(255,0,0)","rgb(0,0,255)"];
            for(i=0; i<count; i++){
                ctx.fillStyle=fillColors[i];
                ctx.strokeStyle=strokeColors[i];
                ctx.fillRect(i*(offset+size)+offset,offset,size,size);
                ctx.strokeRect(i*(offset+size)+offset,(2*offset)+size,size,size);
            }
        </script>
    </body>
</html>